package com.llkj.contractmanagement.customview;


import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.llkj.contractmanagement.R;
import com.llkj.contractmanagement.utils.StringUtil;


public class MyDialog extends Dialog implements View.OnClickListener {

    private TextView tv_content;
    private Button btn_right, btn_left;
    private ItemClickListener itemClickListener;
    private String content, rightText, leftText;

    public void setRightText(String rightText) {
        this.rightText = rightText;
    }


    public void setLeftText(String leftText) {
        this.leftText = leftText;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setbtnColorForGray( ) {
        this.btn_left.setTextColor(Color.GRAY);
    }

    public MyDialog(Context context, String content, int theme) {
        super(context, theme);
        this.content = content;
    }

    public void setItemClickListener(ItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog_public);
        this.setCanceledOnTouchOutside(true);
        tv_content = (TextView) findViewById(R.id.tv_content);
        btn_right = (Button) findViewById(R.id.btn_right);
        btn_left = (Button) findViewById(R.id.btn_left);
        tv_content.setText(content);
        if (!StringUtil.isEmpty(rightText)) {
            btn_right.setText(rightText);
        }
        if (!StringUtil.isEmpty(leftText)) {
            btn_left.setText(leftText);
        }
        btn_right.setOnClickListener(this);
        btn_left.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_right:
                if (itemClickListener != null) {
                    itemClickListener.right();
                    dismiss();
                }
                break;
            case R.id.btn_left:
                if (itemClickListener != null) {
                    itemClickListener.left();
                    dismiss();
                }
                break;
            default:
                break;
        }
    }

    public interface ItemClickListener {
        void left();

        void right();
    }
}
